<?php

namespace app\common\model\user;

use app\common\model\BaseModel;

/**
 * 用户返现劵记录模型
 * Class Couponlog
 * @package app\common\model\user
 */
class CouponLog extends BaseModel
{
    protected $name = 'user_coupon_log';

    /**
     * 添加用户返现劵
     * @param $user_id
     * @param $order_no
     * @param $coupon_money
     * @param $user_return_days
     * @param $scene
     */
    public static function setIncCoupon($user_id, $order_no, $coupon_money, $user_return_days, $scene = 10)
    {
        // 新增积分变动明细
        self::add([
            'user_id' => $user_id,
            'order_no' => $order_no,
            'coupon_money' => sprintf('%.2f', $coupon_money),
            'user_return_days' => $user_return_days,
            'scene' => $scene,
            'become_time' => strtotime("+{$user_return_days}days", time())
        ]);
    }

    /**
     * 新增记录
     * @param $data
     */
    public static function add($data)
    {
        $static = new static;
        $static->save(array_merge(['wxapp_id' => $static::$wxapp_id], $data));
    }

    /**
     * 优惠券详情
     * @param $log_id
     * @return null|static
     * @throws \think\exception\DbException
     */
    public static function detail($log_id)
    {
        return self::get($log_id);
    }

}